
const tokens = {
  admin: {
    token: 'admin-token'
  },
  editor: {
    token: 'editor-token'
  }
};

const users = {
  'admin-token': {
    roles: ['admin'],
    introduction: 'I am a super administrator',
    avatar: 'https://www.sucaijishi.com/uploadfile/2016/0203/20160203022635285.png?imageView2/0/q/100|watermark/2/text/57Sg5p2Q6ZuG5biCIC8gU1VDQUlKSVNISS5DT00=/font/5oCd5rqQ6buR5L2T/fontsize/300/fill/I0ZGRkZGRg==/dissolve/30/gravity/Center/dx/0/dy/0',
    name: 'Super Admin'
  },
  'editor-token': {
    roles: ['编辑'],
    introduction: 'I am an editor',
    avatar: 'https://www.sucaijishi.com/uploadfile/2016/0203/20160203022635285.png?imageView2/0/q/100|watermark/2/text/57Sg5p2Q6ZuG5biCIC8gU1VDQUlKSVNISS5DT00=/font/5oCd5rqQ6buR5L2T/fontsize/300/fill/I0ZGRkZGRg==/dissolve/30/gravity/Center/dx/0/dy/0',
    name: 'Andy'
  }
};

export default [
  // user login
  {
    url: '/vue-element-admin/user/login',
    method: 'post',
    response: config => {
      const { username } = config.body;
      const token = tokens[username];

      // mock error
      if (!token) {
        return {
          code: 60204,
          message: 'Account and password are incorrect.'
        };
      }

      return {
        code: 20000,
        data: token
      };
    }
  },

  // get user info
  {
    url: '/vue-element-admin/user/info',
    method: 'get',
    response: config => {
      const { token } = config.query;
      const info = users[token];

      // mock error
      if (!info) {
        return {
          code: 50008,
          message: 'Login failed, unable to get user details.'
        };
      }

      return {
        code: 20000,
        data: info
      };
    }
  },

  // user logout
  {
    url: '/vue-element-admin/user/logout',
    method: 'post',
    response: () => {
      return {
        code: 20000,
        data: 'success'
      };
    }
  }
];
